package main

import "fmt"

type Humaner interface {
	sayhi()
}

type Student struct {
	name string
	id   int
}

type Teacher struct {
	addr  string
	group string
}

type MyStr string

func (tmp *Student) sayhi() {
	fmt.Printf("Student[%s, %d] sayhi\n", tmp.name, tmp.id)
}

func (tmp *Teacher) sayhi() {
	fmt.Printf("Teacher[%s, %s] sayhi\n", tmp.addr, tmp.group)
}

func (tmp *MyStr) sayhi() {
	fmt.Printf("MyStr[%s] sayhi\n", *tmp)
}

//定义一个普通函数，函数的参数为接口类型
//只有一个函数，可以有不同表现，多态
func WhoSayHi(i Humaner) {
	i.sayhi()
}

func main() {
	s := &Student{"mike", 666}
	t := &Teacher{"bj", "go"}
	var str MyStr = "hello mike"

	WhoSayHi(s)
	WhoSayHi(t)
	WhoSayHi(&str)

	fmt.Printf("======= 切片验证 =======\n")
	x := make([]Humaner, 3)
	x[0] = s
	x[1] = t
	x[2] = &str

	for _, object := range x {
		object.sayhi()
	}

}
